//be carefully this is C51! C51! C51! not C98 not C++
#include <REGX52.H>//AT89C52 single-chip header file
#include <stdio.h>//std input output 

void delay(long ms)
{
	while(ms)
	{
		ms--;
	}
	return;
}
/*
int bit2hex(bit b7, bit b6, bit b5, bit b4, bit b3, bit b2, bit b1, bit b0)
{
	return b7*0x80+b6*0x40+b5*0x20+b4*0x10+b3*0x08+b2*0x04+b1*0x02+b0;
}
*/
void main()
{
	//value define and initialize
	int n0=0;//buzzer time
	int n1=0;//display bit number
	int n2=0;//main time
	int n3=0;//display bit adress
	int n4=0;//P2.4 port
	//unsigned int CAtable[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};//CA display table
	unsigned int CCtable[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};//CC display table
	//point vlaue - 0x80
	
	//port value clearn up
	P0=0;
	P1=0;
	P2=0;
	P3=0;
	
	//main programm
	for(n0=0;n0<6;n0++)
	{
		if(P0==0xFF)
		{
			P0=0;
			P2=0;
		}
		else
		{
			P0=0xFF;
			P2=0x10;
		}
		delay(12000);
	}
	P2=0xFF;
	n0=6000;
	n2=6000;
	while(n2>0)
	{
		if(n0==n2)
		{
			if(n2<1000)
			{
				if(n2<300)
				{
					n4=1;
				}
				else
				{
					if(n4==0)
					{
						n4=1;
					}
					else
					{
						n4=0;
					}
					n0-=30;
				}
			}
			else
			{
				if(n4==0)
				{
					n4=1;
				}
				else
				{
					n4=0;
				}
				n0-=(n2/1000)%10*50;//time between di di Proportion
			}
		}
		n3=0x0E;
		
		for(n1=0;n1<4;n1++)
			{
				switch (n1)
				{
					case 0:
					{
						P0=CCtable[(n2/10000)%10];
						break;
					}
					case 1:
					{
						P0=CCtable[(n2/1000)%10];
						break;
					}
					case 2:
					{
						P0=CCtable[(n2/100)%10]-0x80;
						break;
					}
					case 3:
					{
						P0=CCtable[(n2/10)%10];
						break;
					}
					default:
					{
						P0=CCtable[0];
						break;
					}
				}
				P2=n3+n4*0x10;
				delay(600);
				P2=0x0F+n4*0x10;
				n3=n3*2-0x0F;
			}
		n2-=10;
	}
	P2=0;
	P3=0;
	while(1)
	{
		P0=0xFF;
		P2=0x10;
	}
	return;
}